//
//  ServiceGuidanceViewController.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 15/12/29.
//  Copyright © 2015年 GripMeMory. All rights reserved.
//

#import "ServiceGuidanceViewController.h"
#import "TableViewDataSource.h"

#import "ServiceGuidanceCell.h"
#import "ServiceGuidanceModel.h"

#define kBottomViewHeight 54
#define kBottomViewIconTopMargin 15
#define kBottomViewIconLeftMargin 100

static NSString * const cellIdentifier = @"ServiceGuidanceCellName";

@interface ServiceGuidanceViewController () <UITableViewDataSource, UITableViewDelegate>

@end

@implementation ServiceGuidanceViewController

{
    UITableView *_tableView;
    NSArray *_questionList1;
    NSArray *_questionList2;
}

#pragma mark - View Controller Life Cycle

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController popToRootViewControllerAnimated:NO];
    self.navigationController.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self fakeValue];
    [self customNav];
    [self customUI];
    [self customBottomView];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Fake Value

- (void)fakeValue{
    _questionList1 = @[@"如何进行免费注册?", @"如何申请竞价?", @"如何进行在线报名?", @"如何进行在线交纳保证金?"];
    _questionList2 = @[@"网络竞价大厅使用规则", @"动态报价大厅使用规则", @"网络采购大厅使用规则", @"诉讼资产大厅使用规则"];
}

#pragma mark - Custom NavigationBar

- (void)customNav{
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarButtonItemClick:)];
    self.navigationItem.leftBarButtonItem = bbi;
    
    self.title = @"服务指引";
}

#pragma mark - Custom User Interface

- (void)customUI{
    [self setupTableView];
}

- (void)setupTableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, UISCREENHEIGHT) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.sectionHeaderHeight = 20;
    _tableView.sectionFooterHeight = 0;
    [_tableView registerClass:[ServiceGuidanceCell class] forCellReuseIdentifier:cellIdentifier];
    [self.view addSubview:_tableView];
    [_tableView reloadData];
}

- (void)customBottomView{
    
    UIImageView *bottomView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.bottom - kBottomViewHeight, self.view.width, kBottomViewHeight)];
    bottomView.contentMode = UIViewContentModeScaleToFill;
    bottomView.image = [UIImage imageNamed:@"TAB.9.png"];
    
    UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(kBottomViewIconLeftMargin, kBottomViewIconTopMargin, bottomView.height - 2 * kBottomViewIconTopMargin, bottomView.height - 2 * kBottomViewIconTopMargin)];
    iconView.image = [UIImage imageNamed:@"电话"];
    [bottomView addSubview:iconView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(iconView.right + kBottomViewIconTopMargin, 0, 200, bottomView.height)];
    label.text = @"客服咨询：4006-010-661";
    label.textColor = [UIColor whiteColor];
    [bottomView addSubview:label];
    
    [self.view addSubview:bottomView];
    
}

#pragma mark - TableView DataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return _questionList1.count;
    }else if(section == 1){
        return _questionList2.count;
    }else{
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ServiceGuidanceCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    if (!cell) {
        cell = [[ServiceGuidanceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    if (indexPath.section == 0) {
        [cell configureCellWithModel:_questionList1[indexPath.row]];
    }else if(indexPath.section == 1){
        [cell configureCellWithModel:_questionList2[indexPath.row]];
    }
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"常见问题";
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

#pragma mark - TableView Delegate

#pragma mark - Bar Item Action

- (void)backBarButtonItemClick:(UIBarButtonItem *)bbi{
    [self.navigationController popToRootViewControllerAnimated:NO];
}

@end
